package com.computercourse.learning.dao;

import com.computercourse.framework.domain.learning.CicUserAnswer;
import com.computercourse.framework.domain.learning.CicUserNote;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description:
 * @author: yuanfeng
 * @date: Created in 2020/2/15 4:05 下午
 * @version: 1.0
 */
@Repository
public interface CicUserAnswerRepository extends JpaRepository<CicUserAnswer,String> {

    //根据用户Id和课程Id查询
    List<CicUserAnswer> findAllByCourseIdOrderByAnswerTimeDesc(String courseId);

    //根据用户Id和课程Id查询
    List<CicUserAnswer> findAllByCourseIdAndPerfectAnswerEqualsOrderByModifyTimeDesc(@Param("courseId") String courseId,@Param("perfectAnswer") Integer perfectAnswer);

    CicUserAnswer findCicUserAnswerByCourseIdAndAndAnswerId(@Param("courseId") String courseId, @Param("answerId") String answerId);

    @Modifying
    @Query(value = "update CicUserAnswer set perfectAnswer = 0 where courseId = :courseId and answerId = :answerId")
    int cancelPerfectNote(@Param("courseId") String courseId,@Param("answerId") String answerId);

}
